package cn.wk.basic.controller;

import cn.wk.basic.exception.DiyException;
import cn.wk.basic.service.IVerificationCodeService;
import cn.wk.basic.utils.AjaxResult;
import cn.wk.user.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/verification")
public class VerificationCodeController {
    @Autowired
    private IVerificationCodeService verificationCodeService;

    /**
     * 用户注册发送验证码
     * @param user
     * @return
     * @throws DiyException
     */
    @RequestMapping("/sendMobileCode")
    public AjaxResult sendMobileCode(@RequestBody User user) throws DiyException {
        System.out.println(user);
        //通过传进去的手机号去进行业务处理
        try{
            verificationCodeService.sendMobileCode(user.getPhone());
            return new AjaxResult();
        }catch(Exception e){
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }

    /**
     * 用户通过微信绑定手机发送验证码
     * @param user
     * @return
     * @throws DiyException
     */
    @RequestMapping("/sendCode")
    public AjaxResult sendCode(@RequestBody User user) throws DiyException {
        System.out.println(user);
        //通过传进去的手机号去进行业务处理
        try{
            verificationCodeService.sendCode(user.getPhone());
            return new AjaxResult();
        }catch(Exception e){
            e.printStackTrace();
            return new AjaxResult(e.getMessage());
        }
    }
}
